package com.itlong.cloud.app.resource;

import com.alibaba.fastjson.JSONObject;
import com.itlong.cloud.POJO.PO.DevicePadInfoPO;
import com.itlong.cloud.POJO.PO.SpecialDevicePadInfoPO;
import com.itlong.cloud.POJO.VO.app.*;
import com.itlong.cloud.POJO.VO.property.CloudDeviceUpdateInfoVO;
import com.itlong.cloud.POJO.VO.property.CloudElevatorVO;
import com.itlong.cloud.app.service.IAppHomeService;
import com.itlong.cloud.app.service.IAppPadFaceService;
import com.itlong.cloud.user.app.IAppPadFaceServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *     平板人脸接口代理实现
 * </desc>
 *
 * @createDate 2018/05/14
 */
@RestController
public class AppPadFaceServiceResource implements IAppPadFaceServiceClient {
    @Autowired
    IAppPadFaceService iAppPadFaceService;
    @Autowired
    IAppHomeService iAppHomeService;

    /**
     * <desc>
     *      判断项目是否禁用。
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Qiang.S
     * @createDate 2018-06-13
     */
    @Override
    @RequestMapping(path = "/padFace/checkProjectForbidden",method = RequestMethod.POST)
    public Integer checkProjectForbidden(@RequestParam("projectId") String projectId) throws Exception{
        return iAppPadFaceService.checkProjectForbidden(projectId);
    }

    /**
     * <desc>
     *      设备验证(梯控)。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param deviceId 项目ID
     * @param elevatorType 电梯类型
     * @param isFaceRecognition 是否支持人脸识别
     * @return
     * @author Qiang.S
     * @createDate 2018-05-14
     */
    @Override
    @RequestMapping(path = "/padFace/elevatorAuthorityCheck",method = RequestMethod.POST)
    public String elevatorAuthorityCheck(@RequestParam("projectId") String projectId,@RequestParam("deviceId") String deviceId,
                                         @RequestParam("elevatorType") String elevatorType,@RequestParam("isFaceRecognition") String isFaceRecognition) throws Exception{
        return iAppPadFaceService.elevatorAuthorityCheck(projectId,deviceId,elevatorType,isFaceRecognition);
    }

    /**
     * <desc>
     *      设备验证(群控器)。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param deviceId 项目ID
     * @return
     * @author Qiang.S
     * @createDate 2018-05-14
     */
    @Override
    @RequestMapping(path = "/padFace/controllerAuthorityCheck",method = RequestMethod.POST)
    public String controllerAuthorityCheck(@RequestParam("projectId") String projectId,@RequestParam("deviceId") String deviceId) throws Exception{
        return iAppPadFaceService.controllerAuthorityCheck(projectId,deviceId);
    }

    /**
     * <desc>
     *      设备验证(门禁)。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param deviceId 项目ID
     * @param isFaceRecognition 是否支持人脸识别
     * @return
     * @author Qiang.S
     * @createDate 2018-05-14
     */
    @Override
    @RequestMapping(path = "/padFace/entranceAuthorityCheck",method = RequestMethod.POST)
    public String entranceAuthorityCheck(@RequestParam("projectId") String projectId,@RequestParam("deviceId") String deviceId,
                                         @RequestParam("isFaceRecognition") String isFaceRecognition) throws Exception{
        return iAppPadFaceService.entranceAuthorityCheck(projectId,deviceId,isFaceRecognition);
    }

    /**
     * <desc>
     *      登陆验证。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param userName 账号
     * @param password 密码
     * @return
     * @author Qiang.S
     * @createDate 2018-05-14
     */
    @RequestMapping(path = "/padFace/engineerLoginVerify",method = RequestMethod.POST)
    public Integer engineerLoginVerify(@RequestParam("projectId") String projectId,@RequestParam("userName") String userName,@RequestParam("password") String password) throws Exception{
        return iAppPadFaceService.engineerLoginVerify(projectId,userName,password);
    }

    /**
     * <desc>
     *      登陆项目验证。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param userName 账号
     * @return
     * @author Qiang.S
     * @createDate 2018-06-08
     */
    @RequestMapping(path = "/padFace/engineerLoginProjectVerify",method = RequestMethod.POST)
    public Integer engineerLoginProjectVerify(@RequestParam("projectId") String projectId,@RequestParam("userName") String userName) throws Exception{
        return iAppPadFaceService.engineerLoginProjectVerify(projectId,userName);
    }

    /**
     * <desc>
     *      工程人员帐号是否存在验证。
     * <desc/>
     *
     * @param userName 账号
     * @return
     * @author Qiang.S
     * @createDate 2018-06-11
     */
    @RequestMapping(path = "/padFace/engineerLoginExistsVerify",method = RequestMethod.POST)
    public Integer engineerLoginExistsVerify(@RequestParam("userName") String userName) throws Exception{
        return iAppPadFaceService.engineerLoginExistsVerify(userName);
    }

    /**
     * <desc>
     *      平板获取广告(梯控)。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param deviceId 项目ID
     * @return
     * @author Qiang.S
     * @createDate 2018-05-15
     */
    @Override
    @RequestMapping(path = "/padFace/getElevatorAD",method = RequestMethod.POST)
    public List<AppPadADVO> getElevatorAD(@RequestParam("projectId") String projectId, @RequestParam("deviceId") String deviceId) throws Exception{
        return iAppPadFaceService.getElevatorAD(projectId,deviceId);
    }

    /**
     * <desc>
     *      平板获取广告(门禁)。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param deviceId 项目ID
     * @return
     * @author Qiang.S
     * @createDate 2018-05-15
     */
    @Override
    @RequestMapping(path = "/padFace/getEntranceAD",method = RequestMethod.POST)
    public List<AppPadADVO> getEntranceAD(@RequestParam("projectId") String projectId,@RequestParam("deviceId") String deviceId) throws Exception{
        return iAppPadFaceService.getEntranceAD(projectId,deviceId);
    }

    /**
     * <desc>
     *     通过projectId和deviceId获取deviceUnique。
     * <desc/>
     *
     * @param type 设备类型
     * @param projectId 项目编号
     * @param deviceId 设备机号
     * @return
     * @author Qiang.S
     * @createDate 2018-05-16
     */
    @Override
    @RequestMapping(path = "/padFace/getDeviceUnique",method = RequestMethod.POST)
    public AppPadDeviceVO getDeviceUnique(@RequestParam("type") String type,
                                          @RequestParam("projectId") String projectId,
                                          @RequestParam("deviceId") String deviceId) throws Exception{
        return iAppPadFaceService.getDeviceUnique(type,projectId,deviceId);
    }

    /**
     * <desc>
     *      获取用户账户金额。
     * <desc/>
     *
     * @param userId 用户编号
     * @return
     * @author shengen.T
     * @createDate 2018-05-24
     */
    @Override
    @RequestMapping(path = "/padFace/getUserAccountMoney",method = RequestMethod.POST)
    public BigDecimal getUserAccountMoney(@RequestParam("userId") String userId) throws Exception{
        return iAppPadFaceService.getUserAccountMoney(userId);
    }

    /**
     * <desc>
     *     获取平板更新信息。
     * <desc/>
     *
     * @param type 更新类型；1为人脸识别客户端，2为人脸识别服务端
     * @return
     * @author Qiang.S
     * @createDate 2018-05-31
     */
    @Override
    @RequestMapping(path = "/padFace/getPadProgramInfo",method = RequestMethod.POST)
    public AppPadProgramInfoVO getPadProgramInfo(@RequestParam(value = "type",required = false) String type) throws Exception{
        return iAppPadFaceService.getPadProgramInfo(type);
    }

    /**
     * <desc>
     *      判断当前平板设备唯一码的设备是否存在或是否被禁用。
     * <desc/>
     *
     * @param padDeviceUnique 设备唯一码
     * @return
     * @author Juguang.S
     * @createDate 2019-01-18
     */
    @RequestMapping(path = "/padFace/getPadDeviceExist",method = RequestMethod.POST)
    public String getPadDeviceExist(@RequestParam("padDeviceUnique") String padDeviceUnique) {
        return iAppPadFaceService.getPadDeviceExist(padDeviceUnique);
    }

    /**
     * <desc>
     *      根据baiduId来更新绑定百度识别授权码的设备信息。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param emId emId
     * @param baiduId 百度ID
     * @param padDeviceUnique 平板设备唯一码
     * @param requestType 请求类型  1代表离线验证接口调用  2代表绑定激活码接口调用
     * @return 百度识别码
     * @author Juguang.S
     * @createDate 2019-01-18
     */
    @Override
    @RequestMapping(path = "/padFace/bingBaiDuAuthCode",method = RequestMethod.POST)
    public String bingBaiDuAuthCode(@RequestParam("projectId") String projectId,
                                    @RequestParam("emId") String emId,
                                    @RequestParam("baiduId") String baiduId,
                                    @RequestParam("padDeviceUnique") String padDeviceUnique,
                                    @RequestParam("requestType") String requestType) throws Exception {
        return iAppPadFaceService.bingBaiDuAuthCode(projectId, emId, baiduId,padDeviceUnique,requestType);
    }

    /**
     * <desc>
     *      根据baiduId来更新绑定百度识别授权码的设备信息。
     * <desc/>
     *
     * @param baiduId 百度ID
     * @param code 3激活成功4激活失败
     * @param msg 失败信息
     * @return 百度识别码
     * @author Qiang.S
     * @createDate 2019-08-06
     */
    @Override
    @RequestMapping(path = "/padFace/reportBaiDuAuthCode", method = RequestMethod.POST)
    public Integer reportBaiDuAuthCode(@RequestParam("baiduId") String baiduId,
                                       @RequestParam("code") String code,
                                       @RequestParam("msg") String msg) throws Exception {
        return iAppPadFaceService.reportBaiDuAuthCode(baiduId, code, msg);
    }

    /**
     * <desc>
     *      校验该平板机号有没被其它设备占用
     * <desc/>
     *
     * @param baiduId 百度ID
     * @param padDeviceUnique 平板设备唯一码
     * @return 百度识别码
     * @author Juguang.S
     * @createDate 2019-03-20
     */
    @Override
    @RequestMapping(path = "/padFace/isDeviceIdUserd",method = RequestMethod.POST)
    public Integer isDeviceIdUserd(@RequestParam("baiduId") String baiduId,
                                   @RequestParam("padDeviceUnique") String padDeviceUnique) {
        return iAppPadFaceService.isDeviceIdUserd(baiduId,padDeviceUnique);
    }

    /**
     * <desc>
     *      根据人脸编号获取电梯信息。
     * <desc/>
     *
     * @param uId 百度人脸编号
     * @return
     * @author Qiang.S
     * @createDate 2019-02-27
     */
    @Override
    @RequestMapping(path = "/padFace/getElevatorInfoByFaceId",method = RequestMethod.POST)
    public List<AppPadVisitorElevatorInfoVO> getElevatorInfoByFaceId(@RequestParam("uId")String uId) throws Exception{
        return iAppPadFaceService.getElevatorInfoByFaceId(uId);
    }

    /**
     * <desc>
     *      根据人脸编号获取门禁信息。
     * <desc/>
     *
     * @param uId 百度人脸编号
     * @return
     * @author Qiang.S
     * @createDate 2019-02-27
     */
    @Override
    @RequestMapping(path = "/padFace/getDoorInfoByFaceId",method = RequestMethod.POST)
    public List<AppDoorDevicesVO> getDoorInfoByFaceId(@RequestParam("uId")String uId) throws Exception{
        return iAppPadFaceService.getDoorInfoByFaceId(uId);
    }

    /**
     * <desc>
     *      获取项目的设备过期时间。
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Juguang.S
     * @createDate 2019-08-06
     */
    @Override
    @RequestMapping(path = "/padFace/getDeviceCloudServiceCostEndTime",method = RequestMethod.POST)
    public List<Map<String, Object>> getDeviceCloudServiceCostEndTime(@RequestParam("projectId") String projectId){
        return iAppPadFaceService.getDeviceCloudServiceCostEndTime(projectId);
    }

    /**
     * <desc>
     *      获取物业的联系方式。
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Juguang.S
     * @createDate 2019-08-15
     */
    @RequestMapping(path = "/padFace/getPropertyPhone",method = RequestMethod.POST)
    public String getPropertyPhone(@RequestParam("projectId") String projectId){
        return iAppPadFaceService.getPropertyPhone(projectId);
    }

    /**
     * <desc>
     *      注册平板iot。
     * <desc/>
     *
     * @param padDeviceUnique 平板机号
     * @return
     * @author Qiang.S
     * @createDate 2019-07-10
     */
    @Override
    @RequestMapping(path = "/padFace/registerPadIot",method = RequestMethod.POST)
    public CloudElevatorVO registerPadIot(@RequestParam("padDeviceUnique")String padDeviceUnique) throws Exception{
        return iAppPadFaceService.registerPadIot(padDeviceUnique);
    }

    /**
     * <desc>
     *      设备升级。
     * <desc/>
     *
     * @param deviceType 升级包类型；4 维护程序，5 业务程序，6 桌面程序，7 通信程序
     * @param deviceUnique 设备编号
     * @return
     * @author Qiang.S
     * @createDate 2019/12/06
     */
    @Override
    @RequestMapping(path = "/padFace/deviceUpdate",method = RequestMethod.POST)
    public List<CloudDeviceUpdateInfoVO> deviceUpdate(@RequestParam("deviceUnique")String deviceUnique, @RequestParam(value = "deviceType",required = false)String deviceType) throws Exception{
        return iAppPadFaceService.deviceUpdate(deviceUnique,deviceType);
    }

    /**
     * <desc>
     *      根据deviceUnique批量获取设备地址
     * </desc>
     *
     * @param bindDeviceUnique 平板绑定的的deviceUnique，多个以逗号隔开
     * @return
     * @Author Zhu.yj
     * @createDate  2019/12/16
     */
    @Override
    @RequestMapping(path = "/padFace/updatePadBridgeInfo",method = RequestMethod.POST)
    public Integer updatePadBridgeInfo(@RequestParam("bindDeviceUnique") String bindDeviceUnique, @RequestParam("padDeviceUnique") String padDeviceUnique, @RequestParam("projectId") String projectId, @RequestParam("mac") String mac) throws Exception {
        return iAppPadFaceService.updatePadBridgeInfo(bindDeviceUnique,padDeviceUnique,projectId,mac);
    }

    /**
     * <desc>
     *      获取平板绑定的设备数量
     * </desc>
     *
     * @param bindDeviceUniques
     * @return
     * @Author Zhu.yj
     * @createDate  2020/1/2
     */
    @Override
    @RequestMapping(value = "/padFace/getBindDeviceCount",method = RequestMethod.POST)
    public Integer getBindDeviceCount(@RequestParam("bindDeviceUniques") String bindDeviceUniques, @RequestParam("deviceType") String deviceType) throws Exception {
        return iAppPadFaceService.getBindDeviceCount(bindDeviceUniques,deviceType);
    }

    /**
     * <desc>
     *      校验要绑定的设备中是否有普通门禁
     * </desc>
     *
     * @param bindDeviceUniques 绑定的门禁设备编号
     * @return 普通门禁数量
     * @Author Zhu.yj
     * @createDate  2020/1/8
     */
    @RequestMapping(value = "/padFace/checkCommonEntranceExist",method = RequestMethod.POST)
    public Integer checkCommonEntranceExist(@RequestParam("bindDeviceUniques") String bindDeviceUniques) throws Exception{
        return iAppPadFaceService.checkCommonEntranceExist(bindDeviceUniques);
    }

    /**
     * <desc>
     *      根据平板绑定普通门禁编号处理数据
     * </desc>
     *
     * @param bindDeviceUniques 绑定的门禁设备编号
     * @return 普通门禁数量
     * @Author Qiang.S
     * @createDate  2020/02/20
     */
    @RequestMapping(value = "/padFace/getUserInfoByRoleId",method = RequestMethod.POST)
    public Map<String,Object> getUserInfoByRoleId(@RequestParam("bindDeviceUniques") String bindDeviceUniques) throws Exception{
        return iAppPadFaceService.getUserInfoByRoleId(bindDeviceUniques);
    }

    /**
     * <desc>
     *      平板人脸识别仪上报设备的能力集信息
     * </desc>
     *
     * @param params 信息
     *
     * @Author pengwei
     * @createDate  2020/11/16
     */
    @RequestMapping(value = "/padFace/uploadDeviceInfo",method = RequestMethod.POST)
    public  void   uploadDeviceInfo(@RequestParam  Map<String,String>  params) throws Exception{
        iAppPadFaceService.uploadDeviceInfo(params);
    }

    /**
     * <desc>
     * 获取设备是否存在
     * </desc>
     *
     * @param deviceUnique
     * @return
     * @author caoshuai
     * @createDate 2020/12/10 11:52
     */
    @Override
    @RequestMapping(value = "/padFace/getDevicePadByDeviceUnique",method = RequestMethod.POST)
    public DevicePadInfoPO getDevicePadByDeviceUnique(@RequestParam("deviceUnique") String deviceUnique) {
        return  iAppPadFaceService.getDevicePadByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 保存
     * </desc>
     *
     * @param specialDevicePadInfoPO
     * @return
     * @author caoshuai
     * @createDate 2020/12/10 11:52
     */
    @Override
    @RequestMapping(value = "/padFace/save",method = RequestMethod.POST)
    public Integer save(@RequestBody SpecialDevicePadInfoPO specialDevicePadInfoPO) throws Exception {
        return iAppPadFaceService.save(specialDevicePadInfoPO);
    }
}
